#include "GeneticOperators.h"
#include "FunctionNode.h"
#include "TerminalNode.h"

#include <vector>

namespace jcrada {
    //CROSSOVER OPERATOR

    CrossoverOperator::CrossoverOperator( ) :
    _random_crossover_point( new RandomGsl( ) ),
    _random_node_selection( new RandomGsl( ) ),
    _probability_select_functions( 0.9 ) {

    }

    CrossoverOperator::~CrossoverOperator( ) {
        delete _random_crossover_point;
        delete _random_node_selection;
    }

    Node * CrossoverOperator::crossoverPoint( const TreeOfNodes & parent ) {
        Node* result = NULL;
        std::vector<FunctionNode*>* functions = parent.getFunctionNodes();
        if (functions->size() > 0 && getRandomNodeSelection().nextDouble() < getProbabilityToSelectFunctions()) {
            int crossover_point = getRandomCrossoverPoint().nextInt(0, functions->size());
            result = functions->at(crossover_point);
        } else {
            std::vector<TerminalNode*>* terminals = parent.getTerminalNodes();
            int crossover_point = getRandomCrossoverPoint().nextInt(0, terminals->size());
            result = terminals->at(crossover_point);
            delete terminals;
        }
        delete functions;
        assert(result);
        return result;
    }


    //MUTATION OPERATOR

    MutationOperator::MutationOperator( ) :
    _max_mutation_depth( 2 ),
    _random_mutation_point( new RandomGsl( ) ),
    _random_method( new RandomGsl( ) ) {

    }

    MutationOperator::~MutationOperator( ) {
        delete _random_mutation_point;
        delete _random_method;
    }

    //REPRODUCTION OPERATOR

    ReproductionOperator::ReproductionOperator( ) {

    }

    ReproductionOperator::~ReproductionOperator( ) {

    }



}
